Joining an Array into a String

In this recipe we find out that JavaScript in Navigator can create strings from arrays.

(If you've seen the previous two recipes, this layout will not come as a surprise!)
Fill in the top row of boxes and press the button representing the character that you'd like to have between the array elements.

The words:


The Sentence:

Discussion

The JavaScript engine can combine array elements into an output string. This can be useful when you've used the Array.split() function to turn a string into an array (probably to parse it), and need to get it put back together. Array.join() takes a single argument, which is the character you want separating the array elements in the output string; if you omit the argument, the function joins the elements with commas. If you use an empty string ('') as an argument, the function joins the elements with no separators of any sort between them.

Copyright ©1998 by Charles River Media, All Rights Reserved